package com.neusoft.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.neusoft.bean.PageBean;
import com.neusoft.mapper.RegisterDrugMapper;
import com.neusoft.service.RegisterDrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class RegisterDrugServiceImpl implements RegisterDrugService {
    @Autowired
    RegisterDrugMapper registerDrugMapper;
    @Override
    public PageBean searchRegister(Integer page, Integer pageSize,String caseNumber, String realName) {
        PageHelper.startPage(page,pageSize);
        Page<Map<String,Object>> patient=registerDrugMapper.selectPatient(caseNumber,realName);
        PageBean pageBean=new PageBean();
        pageBean.setRows(patient.getResult());
        pageBean.setCount(patient.getTotal());
        return pageBean;
    }

//    public PageBean searchRegister(@RequestParam String caseNumber, String realName) {
//        Page<Map<String,Object>> patient=registerDrugMapper.selectPatient(caseNumber,realName);
//        PageBean pageBean=new PageBean();
//        pageBean.setRows(patient.getResult());
//        return pageBean;
//    }

    @Override
    public PageBean showMedical(Integer registerId) {
        Page<Map<String,Object>> medical=registerDrugMapper.selectAllByRegisterId(registerId);
        PageBean pageBean=new PageBean();
        pageBean.setRows(medical.getResult());
        return pageBean;
    }

    @Override
    public String giveMedical(Integer registerId) {

        Integer count=registerDrugMapper.updateDrugState(registerId);
        return count==0?"发药失败":"发药成功";
    }

    @Override
    public PageBean searchDropRegister(Integer page, Integer pageSize, String caseNumber, String realName) {

        PageHelper.startPage(page,pageSize);
        Page<Map<String,Object>> patientDropMedical =registerDrugMapper.selectPatientDropMedical(caseNumber,realName);
        PageBean paBe=new PageBean();
        paBe.setRows(patientDropMedical.getResult());
        paBe.setCount(patientDropMedical.getTotal());
        return paBe;
    }

    @Override
    public PageBean showDropMedical(Integer registerId) {
        Page<Map<String,Object>> dropmedical=registerDrugMapper.selectAllDropMedicalByRegisterId(registerId);
        PageBean pageDrop=new PageBean();
        pageDrop.setRows(dropmedical.getResult());
        return pageDrop;
    }

    @Override
    public String refundMedical(Integer registerId, Integer drugId) {
        Integer count=registerDrugMapper.updateDropDrugState(registerId,drugId);
        return count==0?"退药失败":"退药成功";
    }


}
